Java: 9 by Andrew Binstock & Pankaj Kumar

Java: 9 by Andrew Binstock & Pankaj Kumar

Author:Andrew Binstock & Pankaj Kumar [Binstock, Andrew]
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2018-11-24T16:00:00+00:00


Nashorn JavaScript Engine in JDK 9

Handy additions and support for ES6 make Nashorn even more useful.

Nashorn, the JDK’s built-in JavaScript engine, has undergone a variety of improvements in this new release. Before diving into those enhancements, let me briely set the

context for these changes so that their addition makes the most sense.

Background When I started the development of Nashorn in late 2010, I was just looking for a way to experiment with the newly minted invokedynamic (JSR 292) byte-code instruction. The JVM team later adopted Nashorn as a test bed forinvokedynamic, and the Nashorn Project drove much of the performance improvements made to theinvokedynamic implementation.

While this was going on, the Java group was discussing how JavaScript would likely grow to dominate client-side development and that integrating JavaScript with Java would be a critical element of the client/server equation. Rhino—an open source implementation of JavaScript from the Mozilla Foundation that was then the JDK ofering for JavaScript— was getting long in the tooth, and further development was winding down. In November 2012, JDK Enhancement Proposal (JEP) 174, “Nashorn JavaScript Engine,” was approved, which enabled work to begin in earnest to provide a fresh, robust, secure, full-featured implementation of ECMAScript-262 Edition 5.1 (ES5) to run on the Java platform.

Initially, Nashorn found a home in a wide variety of applications, such as app servers, JavaFX applications, utilities, shell scripts, embedded systems, and so on.

Nashorn continues to have broad usage, but its use

appears to have settled into three main areas:

■ The development of JavaScript applications that can be

run on both the client and the server. In the JavaScript

world, this is known as isomorphic development. The advantages are huge for smaller shops that want to build front ends for both desktop and mobile services—a single programming language with a common codebase and rapid delivery. Isomorphic development also scales well for

larger systems.

■ Runtime adaptive or dynamic coding. The term I like to use is soft coding, where portions of an application can be modiied after the application/server is deployed. This capability is used for everything from stored procedures in databases to application coniguration management.

■ Shell scripting. This consists of using JavaScript in areas where bash or Python would traditionally be used.

There is often a lot of debate about Nashorn’s performance on

the JVM compared to native JavaScript performance on platforms such as Google’s V8. Nashorn starts out slower because

it translates the JavaScript to bytecode. After that, Nashorn is

at the mercy of HotSpot to deliver native code. This approach

works well for long-running server applications but not as

well for small and run-once scripts. The main reason we

developed Nashorn in the irst place was to run JavaScript

and Java together seamlessly. Most Nashorn applications do a

great job of orchestrating JavaScript and Java, something that

V8 was not designed to do. 34

ES6 Support The most important issue for JavaScript developers doing isomorphic development is the need to have client/server source code compatibility. With most browsers adopting ECMAScript 6 (ES6) as the standard level of language support for JavaScript, it was essential to bring Nashorn in line.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.